package interview.demo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class MyHashMap {
    public static void main(String[] args) {
        //初始化一组字符串
        List<String> list = new ArrayList<>();
        list.add("hello");
        list.add("Java");
        list.add("python");
        list.add("水到渠成");
        list.add("redis");
        list.add("Jvm");
        list.add("JUC");

        //定义要存放的数组
        String[] tab = new String[8];

        //循环存放
        for (String key : list) {
            //计算索引位置
            int idx = key.hashCode() & (tab.length - 1);
            System.out.println(String.format("key值=%s Idx=%d", key, idx));

            if (null == tab[idx]) {
                tab[idx] = key;
                continue;
            }
            tab[idx] = tab[idx] + "->" + key;
        }
        System.out.println(tab.toString());
    }
}
